/**
 * 
 */
package org.lightmtv.request;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import org.apache.commons.fileupload.FileItem;

/**
 * @author GL
 * 
 * @since 2008-1-10
 */
public class CommonsFileUpload implements FileUpload{

	private FileItem fi;

	public CommonsFileUpload(FileItem fileItem) {
		super();
		this.fi = fileItem;
	}
	public String getPath() {
		return fi.getName();
	}
	public String getName() {
		String n = getPath().replace('\\', '/');
		int i=n.lastIndexOf('/');
		if(i!=-1){
			n=n.substring(i+1);
		}
		return n;
	}
	public String getPerf() {
		String n = getName();
		int i=n.lastIndexOf('.');
		if(i!=-1)
			n=n.substring(0,i-1);
		return n;
	}
	
	public String getSuff() {
		String n = getName();
		int i=n.lastIndexOf('.');
		if(i!=-1)
			return n.substring(i+1);
		else
			return null;
	}
	
	public void delete() {
		fi.delete();
	}
	
	public byte[] get() {
		return fi.get();
	}
	
	public String getContentType() {
		return fi.getContentType();
	}
	
	public String getFieldName() {
		return fi.getFieldName();
	}
	
	public InputStream getInputStream() throws IOException {
		return fi.getInputStream();
	}
	
	public OutputStream getOutputStream() throws IOException {
		return fi.getOutputStream();
	}
	
	public long getSize() {
		return fi.getSize();
	}
	
	public String getString() {
		return fi.getString();
	}
	
	public String getString(String encoding) throws UnsupportedEncodingException {
		return fi.getString(encoding);
	}
	
	public boolean isFormField() {
		return fi.isFormField();
	}
	
	public boolean isInMemory() {
		return fi.isInMemory();
	}
	
	public void write(File file) throws Exception {
		fi.write(file);
	}
}
